<?php
class VisitorsController extends AppController {

    public $helpers = array('Html', 'Form');
    public $components = array('Session');

    public function index() {
        $pageTitle ="Worldwide Seventhday-Adventisth Church - Kwabrafoso: Visitor";
        $in_record_data = $this->Visitor->find('all');
        $this->set(compact('in_record_data','pageTitle'));
    }

    
    public function add(){
    $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Enter Visitor";
     if($_POST){
       // pr($_POST);
        $data['Visitor'] = array(
            'visqtr' => $_POST['visqtr'],
            'visyear' => $_POST['visyear'],
            'visdate' => $_POST['visdate'],
            'visname' => $_POST['visname'],
            'rel' => $_POST['rel'],
            'den' => $_POST['den'],
            'purpose' => $_POST['purpose'],
            'stay' => $_POST['stay'],
            'location' => $_POST['location'],
            'hseadd' => $_POST['hseadd'],
            'telno' => $_POST['telno'],
            'conper' => $_POST['conper'],
            'asnper' => $_POST['asnper']
        );

        if(!$this->Visitor->save($data)){
            $this->Session->setFlash('Error Saving Visitor');
        }else{
             $this->Session->setFlash('Visitor Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','errorMsg'));
}
    
    // A functin to delete Visitor
    public function delete($id = null)
    {
       if (!$id) 
       {
        $this->Session->setFlash('Invalid id for Visitor');
        $this->redirect(array('action' => 'index'));
    }
    if ($this->Visitor->delete($id)) 
    {
        $this->Session->setFlash('Visitor Deleted Please');
    } else 
    {
        $this->Session->setFlash(__('Visitor Not Deleted', true));
    }
    $this->redirect(array('action' => 'index'));
}

    // A functin to edit Visitor
    function edit($id = null){
    $record_id = $id;
    $conditions = array('Visitor.id' => $record_id);
    $record = $this->Visitor->find('first', array('conditions' => $conditions, 'recursive' => 1));
   // pr($record);
            
     $pageTitle ="Worldwide Seventh-day Adventist Church - Kwabrafoso: Visitors List";
     if($_POST){
        //pr($_POST);
        $data['Visitor'] = array(
            'visqtr' => $_POST['visqtr'],
            'visyear' => $_POST['visyear'],
            'visdate' => $_POST['visdate'],
            'visname' => $_POST['visname'],
            'rel' => $_POST['rel'],
            'den' => $_POST['den'],
            'purpose' => $_POST['purpose'],
            'stay' => $_POST['stay'],
            'location' => $_POST['location'],
            'hseadd' => $_POST['hseadd'],
            'telno' => $_POST['telno'],
            'conper' => $_POST['conper'],
            'asnper' => $_POST['asnper']
        );

        if(!$this->Visitor->save($data)){
            $this->Session->setFlash('Error Saving Data');
        }else{
             $this->Session->setFlash('Data Saved');
            $this->redirect('index');
        }
    }

    $this->set(compact('pageTitle','record'));
}

     // A functin to view Records
    public function view($id) {
    if (!$id) {
        throw new NotFoundException(__('Invalid Record'));
    }

    $Visitor = $this->Visitor->findById($id);
    if (!$Visitor) {
        throw new NotFoundException(__('Invalid Record'));
    }
    $this->set('Visitor', $visitor);
}

function report($id = null){
    $record_id = $id;
    $conditions = array('Visitor.id' => $record_id);
    $record = $this->Visitor->find('first', array('conditions' => $conditions, 'recursive' => 1));
//    pr($record);

}

}
?>
